﻿using MediatR;
using Return.Enum;
using SlaughterItem.Common.Infrastructures.Interfaces;
using THE_WIND_RISES.Common.Domans.BasicInformation.MainPlans;
using THE_WIND_RISES.Common.Dtos;

namespace Enterprise_Set.API.Application.Commands.Week2.Mainplan_CRUD
{
    /// <summary>
    /// 修改主生产计划表数据
    /// </summary>
    public class UpMainplanHandler : IRequestHandler<UpMainplanCommand, Result>
    {
        public UpMainplanHandler(IBaseRepository<Mainpalan> mainpalanRepository)
        {
            MainpalanRepository = mainpalanRepository;
        }

        public IBaseRepository<Mainpalan> MainpalanRepository { get; set; }
        public async Task<Result> Handle(UpMainplanCommand request, CancellationToken cancellationToken)
        {
            var result = new Result() { Code = (int)CommonErrorCodes.Update };
            var sql = "update mainpalans set MainplanName=@MainplanName,MainplanContext=@MainplanContext,CreateSection=@CreateSection where MainplanId=@MainplanId;";
            var UpNum = MainpalanRepository.Update(sql, new
            {
                MainplanId=request.MainplanId,
                CreateSection=request.CreateSection,
                MainplanName = request.MainplanName,
                MainplanContext = request.MainplanContext,
            });
            if (UpNum > 0)
            {
                result.Code = (int)CommonErrorCodes.Success;
                return result;
            }
            else
            { 
                return result;
            }
        }
    }
}
